import face_recognition

# 加载已知图片并提取人脸编码
known_image = face_recognition.load_image_file("../image/liuqiangdong2.jpeg")
known_face_encoding = face_recognition.face_encodings(known_image)[0]

# 加载未知图片并提取人脸编码
unknown_image = face_recognition.load_image_file("../image/jack_ma2.jpeg")
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]

# 计算两张人脸编码之间的欧氏距离
distance = face_recognition.face_distance([known_face_encoding], unknown_face_encoding)[0]

print(distance)

# 设置相似度阈值，如果需要更高的精度，可以将阈值降低
threshold = 0.4  # 默认阈值为 0.6

if distance < threshold:
    print(f"匹配成功：这是同一个人！相似度距离 = {distance:.2f}")
else:
    print(f"匹配失败：这不是同一个人。相似度距离 = {distance:.2f}")
